﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VehicleScale.Models;
using VehicleScale.EntityMappers;
using System.Diagnostics;

namespace VehicleScale.DataAccess
{
    public class CompanyInfoDataAccess : BaseDataAccess, ICompanyInfoDataAccess
    {

        #region Properties

        /// <summary>
        /// Search object property
        /// </summary>
        public CompanyInfoModel SearchObject
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

#endregion

        #region Methods
        /// <summary>
        /// Search method
        /// </summary>
        /// <returns></returns>
        public IList<CompanyInfoModel> Searcher()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Get method
        /// </summary>
        /// <returns></returns>
        public CompanyInfoModel Get()
        {
            CompanyInfoModel item = null;
            using (DataClassesDataContext dataContext = new DataClassesDataContext(base.ConnectionString))
            {
                CompanyInfo query = dataContext.CompanyInfos.FirstOrDefault();

                if (query != null) item = CompanyInfoMapper.ToModel(query);
            }

            return item;
        }

        /// <summary>
        /// Get last method
        /// </summary>
        /// <returns></returns>
        public CompanyInfoModel GetLast()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Get all method
        /// </summary>
        /// <returns></returns>
        public IList<CompanyInfoModel> GetAll()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Add item
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool Add(CompanyInfoModel item)
        {
            bool result = false;
            try
            {
                using (DataClassesDataContext dataContext = new DataClassesDataContext(base.ConnectionString))
                {
                    CompanyInfo entity = new CompanyInfo();
                    CompanyInfoMapper.ToEntity(entity, item);
                    dataContext.CompanyInfos.InsertOnSubmit(entity);
                    dataContext.SubmitChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return result;
        }

        /// <summary>
        /// Add collection
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        public bool Add(IList<CompanyInfoModel> collection)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Edit collection
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool Edit(CompanyInfoModel item)
        {
            bool result = false;
            try
            {
                using (DataClassesDataContext dataContext = new DataClassesDataContext(base.ConnectionString))
                {
                    CompanyInfo entity = dataContext.CompanyInfos.FirstOrDefault();
                    if (entity != null)
                    {
                        CompanyInfoMapper.ToEntity(entity, item);
                        dataContext.SubmitChanges();
                        result = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return result;
        }

        public bool Edit(IList<CompanyInfoModel> collection)
        {
            throw new NotImplementedException();
        }

        public bool Delete(CompanyInfoModel item)
        {
            throw new NotImplementedException();
        }

        public bool Delete(IList<CompanyInfoModel> collection)
        {
            throw new NotImplementedException();
        }

        #endregion

    }
}
